/** 
 * All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
 * 
 *SysApiLogController
 * 接口传输日志
 * 
 * 修改纪录
 * 2020-06-29 版本：1.0 zhanglongfei 创建。
 * @version 版本：1.0
 * @author 作者：zhanglongfei
 * 创建日期：2020-06-29
 */

package com.topscomm.sys.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.sys.controller.auto.SysApiLogControllerAuto;
import com.topscomm.basic.util.SQLAdapter;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: zhanglongfei
 * @date: 2020-06-29
 * @description:接口传输日志Controller
 * @modify:
 */
@RestController
@RequestMapping("sys/apiLog")
public class SysApiLogController extends SysApiLogControllerAuto implements ISysApiLogController {
	/**
	 * @author: zhanglongfei
	 * @date: 2020-06-29
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		// 对接系统
		if (paraMap.containsKey("qry_project")) {
			String value = paraMap.get("qry_project").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and project = '{0}' ", value);
		}
		// 单据类型
		if (paraMap.containsKey("qry_sourcetype")) {
			String value = paraMap.get("qry_sourcetype").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and sourcetype = '{0}' ", value);
		}
		// 调用类型
		if (paraMap.containsKey("qry_calltype")) {
			String value = paraMap.get("qry_calltype").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and calltype = '{0}' ", value);
		}
		// 返回状态码
		if (paraMap.containsKey("qry_statuscode")) {
			String value = paraMap.get("qry_statuscode").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and statuscode = '{0}' ", value);
		}
		// 调用日期
		if (paraMap.containsKey("qry_createon")) {
			String value = paraMap.get("qry_createon").toString();
		    if (!StringUtil.isEmpty(value))
		    {
			sql.appendSingle(" and createon > {0} ", SQLAdapter.toDateLong(value + " 00:00:00"));
			sql.appendSingle(" and createon < {0} ", SQLAdapter.toDateLong(value + " 23:59:59"));
		    }
		}
		// 单据编号
		if (paraMap.containsKey("qry_sourceid")) {
			String value = paraMap.get("qry_sourceid").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and sourceid = '{0}' ", value);
		}
		// 接口地址
		if (paraMap.containsKey("qry_url")) {
			String value = paraMap.get("qry_url").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and url like '%{0}%' ", value);
		}
		// Post参数
		if (paraMap.containsKey("qry_postparam")) {
			String value = paraMap.get("qry_postparam").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and postparam like '%{0}%' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: zhanglongfei
	 * @date: 2020-06-29
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}
}

